<template>
  <el-dialog title="编辑供应商" width="40%" :before-close="dialogClose" :visible.sync="show">
    <el-form ref="form" :model="item" label-width="100px">
        <el-form-item label="供应商类别">
          <el-select v-model="item.cid" placeholder="供应商类别">
            <el-option v-for="(item,index) in cate" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="供应商名称">
          <el-input v-model="item.name" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="联系人">
          <el-input v-model="item.user" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="item.phone" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="地址">
           <el-input type="textarea" placeholder="请输入地址" v-model="item.address"></el-input>
        </el-form-item>
        <div align="center">
          <el-button type="primary" @click="add">确定修改</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: 'supplyEdit',
  props:['show','cate','item'],
  data() {
    return {

    }
  },
  created: function() {
    
  },
  methods: {
    dialogClose:function(){
      //this.show = false
      this.$emit("func",{'key':'editShow','type':0})
    },
    add:function(){
      var that = this
      var validate = {
        name:'供应商名称不能为空',
        cid:'供应商类别不能为空',
        user:'联系人不能为空',
        phone:'电话不能为空'
      }
      for(var x in validate){
        if(!this.item[x]){
          this.$message.error(validate[x]);
          return false;
          break;
        }
      }
      this.$post('supply/add',this.item).then((res) => {
          if(res.code == 1){
            that.$message.success(res.msg);
            that.$emit("func",{'key':'editShow','type':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>